package org.dfzt.modules.online.cgform.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.*;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Scanner;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

public class k {
    public static boolean b = Boolean.TRUE.booleanValue();

    private static String c;
    private static String d;
    private static String e;
    public static String a;

    public static String getssss() {
        if ("".equals(d) || d == null) {
            String str = "";
            str = getMa() + getProcessorId() + getMotherboardSN();
            a = m.c(str);
            d = m.c(a.toUpperCase() + getLicTime() + getNetLic() + "P5P5");
        }
        return d.toUpperCase();
    }


    public static String getmachine_code() {
        if ("".equals(d) || d == null) {
            String str = "";
            str = getMa() + getProcessorId() + getMotherboardSN();
            a = m.c(str);
        }
        return a.toUpperCase();
    }


    public static String getssssserver() {
        if ("".equals(e) || e == null) {
            String str = "";

            str = getMa() + getProcessorId() + getMotherboardSN();
            a = m.c(str);
            e = m.c(a.toUpperCase() + getNetLic() + "9999");
        }
        return e.toUpperCase();
    }


    private static String getProcessorId() {
        String str = "CPUID000";
        try {
            Process process = Runtime.getRuntime().exec(new String[]{"wmic", "cpu", "get", "ProcessorId"});
            process.getOutputStream().close();
            Scanner scanner = new Scanner(process.getInputStream());
            String str1 = scanner.next();
            str = scanner.next();
        } catch (Exception exception) {
        }


        return str;
    }


    private static String a(String paramString) {
        String str = "";
        try {
            File file = File.createTempFile("damn", ".vbs");
            file.deleteOnExit();
            FileWriter fileWriter = new FileWriter(file);
            String str1 = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nSet objDrive = colDrives.item(\"" + paramString + "\")\nWscript.Echo objDrive.SerialNumber";

            fileWriter.write(str1);
            fileWriter.close();
            Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str2;
            while ((str2 = bufferedReader.readLine()) != null) {
                str = str + str2;
            }
            bufferedReader.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return str.trim();
    }


    private static String getMotherboardSN() {
        String str = "ZBXLH000";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fileWriter = new FileWriter(file);
            String str1 = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\nSet colItems = objWMIService.ExecQuery _ \n   (\"Select * from Win32_BaseBoard\") \nFor Each objItem in colItems \n    Wscript.Echo objItem.SerialNumber \n    exit for  ' do the first cpu only! \nNext \n";
            fileWriter.write(str1);
            fileWriter.close();
            Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str2;
            while ((str2 = bufferedReader.readLine()) != null) {
                str = str + str2;
            }
            bufferedReader.close();
        } catch (Exception exception) {
        }


        return str.trim();
    }


    private static String getLicTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        return simpleDateFormat.format(new Date());
    }


    public static boolean a() {
        Date date1 = new Date();
        String str = "2015-04-18";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date2 = null;
        try {
            date2 = simpleDateFormat.parse(str);
        } catch (Exception exception) {

            exception.printStackTrace();
        }
        return date2.before(date1);
    }


    private static String getNetLic() {
        String str = "A0001";
        try {
            ResourceBundle resourceBundle = org.dfzt.modules.online.cgform.util.c.a();
            if (resourceBundle == null) {
                resourceBundle = ResourceBundle.getBundle("jeecglic");
            }
            str = resourceBundle.getString("licence.key");
        } catch (Exception exception) {
        }

        return str;
    }


    private static String getMa() {
        return org.dfzt.modules.online.cgform.util.e.a();
    }


    private static String getMaOld() {
        if (org.dfzt.modules.online.cgform.util.l.c((Object)org.dfzt.modules.online.cgform.util.k.c)) {
            return org.dfzt.modules.online.cgform.util.k.c;
        }
        String str1 = getOSName();
        String str2 = getSystemRoot() + "/system32/ipconfig /all";
        String str3 = null;
        if (str1.startsWith("windows")) {
            if (str1.equals("windows xp")) {
                str3 = b(str2);
            } else if (str1.equals("windows 2003")) {
                str3 = b(str2);
            } else {
                str3 = getWindow7Ma();
            }
        } else if (str1.startsWith("linux")) {
            str3 = getLinuxMa();
        } else {
            str3 = getUnixMa();
        }
        c = str3;
        return str3;
    }


    private static String getOSName() {
        return System.getProperty("os.name").toLowerCase();
    }


    private static String b(String paramString) {
        String str = null;
      BufferedReader bufferedReader = null;
      Process process = null;

        try {
            process = Runtime.getRuntime().exec(paramString);
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {
                if (str1.indexOf("本地连接") != -1) {
                    continue;
                }

                i = str1.toLowerCase().indexOf("physical address");
                if (i != -1) {
                    i = str1.indexOf(":");
                    if (i != -1) {
                        str = str1.substring(i + 1).trim();
                    }
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return str;
    }


    private static String getWindow7Ma() {
        InetAddress inetAddress = null;
        try {
            inetAddress = InetAddress.getLocalHost();
        } catch (UnknownHostException unknownHostException) {
            unknownHostException.printStackTrace();
        }

        byte[] arrayOfByte = null;
        try {
            arrayOfByte = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
        } catch (SocketException socketException) {
        }


        StringBuffer stringBuffer = new StringBuffer();
        for (byte b1 = 0; b1 < arrayOfByte.length; b1++) {
            if (b1==0 ) {
                stringBuffer.append("-");
            }

            String str = Integer.toHexString(arrayOfByte[b1] & 0xFF);
            stringBuffer.append((str.length() == 1) ? (Character.MIN_VALUE + str) : str);
        }

        return stringBuffer.toString().toUpperCase();
    }


    private static String getLinuxMa() {
        String str = null;
      BufferedReader bufferedReader = null;
      Process process = null;

        try {
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {
                i = str1.toLowerCase().indexOf("硬件地址");
                if (i != -1) {

                    str = str1.substring(i + 4).trim();
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return str;
    }


    private static String getUnixMa() {
        String str = null;
      BufferedReader bufferedReader = null;
      Process process = null;

        try {
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {

                i = str1.toLowerCase().indexOf("hwaddr");
                if (i != -1) {

                    str = str1.substring(i + "hwaddr".length() + 1).trim();
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }

        return str;
    }


    private static String getSystemRoot() {
        String str1 = null;
        String str2 = null;
//        null = null;
        String str3 = "windir";
        str2 = System.getProperty("os.name").toLowerCase();
        if (str2.startsWith("windows")) {
            str1 = "cmd /c SET";
        } else {
            str1 = "env";
        }
        try {
            Process process = Runtime.getRuntime().exec(str1);
            InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String str = null;
            while ((str = bufferedReader.readLine()) != null) {
                str = str.toLowerCase();
                if (str.indexOf(str3) > -1) {
                    return str.substring(str.indexOf(str3) + str3.length() + 1);
                }
            }

        } catch (Exception exception) {
        }


        return null;
    }


    public static String a(String paramString1, String paramString2, String paramString3) {
        Object object = null;
        StringBuffer stringBuffer = new StringBuffer();


        try {
            TrustManager[] arrayOfTrustManager = {new f()};
            SSLContext sSLContext = SSLContext.getInstance("SSL", "SunJSSE");
            sSLContext.init(null, arrayOfTrustManager, new SecureRandom());

            SSLSocketFactory sSLSocketFactory = sSLContext.getSocketFactory();

            URL uRL = new URL(paramString1);
            HttpURLConnection httpURLConnection = (HttpURLConnection) uRL.openConnection();


            httpURLConnection.setConnectTimeout(4500);
            httpURLConnection.setReadTimeout(4500);

            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            httpURLConnection.setUseCaches(false);

            httpURLConnection.setRequestMethod(paramString2);

            if ("GET".equalsIgnoreCase(paramString2)) {
                httpURLConnection.connect();
            }

            if (null != paramString3) {
                OutputStream outputStream = httpURLConnection.getOutputStream();

                outputStream.write(paramString3.getBytes("UTF-8"));
                outputStream.close();
            }


            InputStream inputStream = httpURLConnection.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

            String str = null;
            while ((str = bufferedReader.readLine()) != null) {
                stringBuffer.append(str);
            }
            bufferedReader.close();
            inputStreamReader.close();

            inputStream.close();
            inputStream = null;
            httpURLConnection.disconnect();
        } catch (ConnectException connectException) {
        } catch (Exception exception) {
        }

        return stringBuffer.toString();
    }
}
